package com.yonyougov.ocm.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.yongov.bill.entity.ocm.Gwapply;
import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.MapListProcessor;
import com.yonyou.iuap.yms.processor.mybatis.MapListMybatisProcessor;
import com.yonyou.ucf.mdf.bill.entity.Gwjiedai;
import com.yonyou.ypd.bill.infrastructure.service.api.IBillQueryRepository;
import com.yonyou.ypd.bill.infrastructure.service.api.IBillRepository;
import com.yonyou.ypd.bill.response.ResponseResult;
import com.yonyou.ypd.bill.response.SuccessResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.imeta.orm.schema.QueryCondition;
import org.imeta.orm.schema.QueryField;
import org.imeta.orm.schema.QuerySchema;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yonyou.iuap.fileservice.sdk.service.CooperationFileDownloadService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = {"/menhu/api"})
@Slf4j
public class MenhuApiController {

    @Resource
    private IBillQueryRepository iBillQueryRepository;

    @Resource
    private IBillRepository billRepository;


    @Resource
    private IYmsJdbcApi iYmsJdbcApi;



    @Resource
    private CooperationFileDownloadService cooperationFileDownloadService;

    /**
     * 测试
     */
    @PostMapping("/test")
    public ResponseResult createPayVoucher(HttpServletRequest request, @RequestBody JSONObject map) {

        String id = map.getString("id");
        String uul = cooperationFileDownloadService.queryDownloadUrl(id);
        return new SuccessResponseResult(uul);
    }


    @RequestMapping("/test2")
    public ResponseResult test2(HttpServletRequest request, @RequestBody JSONObject map) {


        List<Map> list = iYmsJdbcApi.queryForList("select *  from  ocm_gwapply", new MapListProcessor());


        return new SuccessResponseResult(list);
    }


    @RequestMapping("/query2")
    public ResponseResult query2(HttpServletRequest request, @RequestBody JSONObject map) {

        QuerySchema querySchema = QuerySchema.create();
        querySchema.selectFields(Collections.singletonList(new QueryField("*")));
        querySchema.appendQueryCondition(QueryCondition.name("bz").eq("1747054173598"));


        List ll = iBillQueryRepository.queryBySchema("cxocm.cxocm.gwapply", querySchema);

        return new SuccessResponseResult(ll);
    }


    @RequestMapping("/insert2")
    public ResponseResult insert2(HttpServletRequest request, @RequestBody JSONObject map) {


        Gwapply vo = new Gwapply();
        vo.setDr(0);
        vo.setBz(System.currentTimeMillis() + "");
        vo.setYtenantId("123");


        Gwapply vo2 = new Gwapply();
        vo2.setDr(0);
        vo.setBz("222");
        billRepository.insertBillDO(vo2);

        billRepository.getYmsJdbcApi();

        return new SuccessResponseResult(iYmsJdbcApi.insert(vo));
    }


}
